//
//  LZMyChangeLinkAccount.m
//  laziz_Consumer
//
//  Created by ZhaoDongBo on 2016/10/28.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZMyChangeLinkAccount.h"

#import "LZMyPersonInfoCommonTableViewCell.h"
#import "LZThirdPartyAccountModel.h"

@interface LZMyChangeLinkAccount() <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) LZThirdPartyAccountModel *facebook_model;
@property (nonatomic, strong) LZThirdPartyAccountModel *twitter_model;

@end

@implementation LZMyChangeLinkAccount

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    self = [super initWithFrame:frame style:style];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setArrThirdParty:(NSMutableArray *)arrThirdParty {
    _arrThirdParty = arrThirdParty;
    self.facebook_model = nil;
    self.twitter_model = nil;
    
    for (LZThirdPartyAccountModel *model in arrThirdParty) {
        if (model.type == 1) {
            self.facebook_model = model;
        }
        else if (model.type == 2) {
            self.twitter_model = model;
        }
    }
    [self reloadData];
}

#pragma
#pragma mark private method

- (void)setup {
    self.backgroundColor = UIColorFromRGB(0xeeeeee,1);
    self.separatorColor = [UIColor clearColor];
    self.dataSource = self;
    self.delegate = self;
}

#pragma
#pragma mark UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    LZMyPersonInfoCommonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
    if (!cell) {
        cell = [[LZMyPersonInfoCommonTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"CellIdentifier"];
    }
    
    cell.type = LZ_MY_INFO_CELL_TYPE_LINKACCOUNT;
    
    if (indexPath.row == 0) {
        cell.iconImageView.image    = [UIImage imageNamed:@"lz_link_twitter"];
        cell.titleLabel.text        = LZLocalizedString(@"share_twitter", @"");     //@"Twitter";
        cell.subTitleLabel.text     = (self.twitter_model==nil)?LZLocalizedString(@"change_notlinked", @""):self.twitter_model.partyAccount;

    }
    else {
        cell.iconImageView.image    = [UIImage imageNamed:@"lz_link_facebook"];
        cell.titleLabel.text        = LZLocalizedString(@"share_facebook", @"");    //@"Facebook";
        cell.subTitleLabel.text     = (self.facebook_model == nil)?LZLocalizedString(@"change_notlinked", @""):self.facebook_model.partyAccount;
    }
    
    return cell;
}

#pragma
#pragma mark UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 55.0f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if(_didSelectRowBlock) {
        if (indexPath.row == 0) {   // twitter
            self.didSelectRowBlock(indexPath, self.twitter_model);
        }
        else {                      // facebook
            self.didSelectRowBlock(indexPath, self.facebook_model);
        }
    }
}


@end
